#!/bin/bash

# install nodejs
function install_nodejs() {
  curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
  echo "export NVM_DIR=\"\$HOME/.nvm\"
        [ -s \"\$NVM_DIR/nvm.sh\" ] && \. \"\$NVM_DIR/nvm.sh\"  # This loads nvm
        [ -s \"\$NVM_DIR/bash_completion\" ] && \. \"\$NVM_DIR/bash_completion\"  # This loads nvm bash_completion" | sed -e 's/^[ ]*//' >> ${USER_PROFILE_PATH}
  source ${USER_PROFILE_PATH}
  nvm install --lts
  nvm use default
}

# install rvm
function install_rvm() {
  gpg --keyserver keyserver.ubuntu.com --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
  \curl -sSL https://get.rvm.io | bash -s -- --ignore-dotfiles
  echo "# Add RVM to PATH for scripting. Make sure this is the last PATH variable chang>
  export PATH=\"\$PATH:\$HOME/.rvm/bin\"" | sed -e 's/^[ ]*//' >> ${USER_PROFILE_PATH}
  echo "[[ -s \"\$HOME/.rvm/scripts/rvm\" ]] && source \"\$HOME/.rvm/scripts/rvm\" # Load RVM into a shell session *as a function*" | sed -e 's/^[ ]*//' >> ${USER_PROFILE_PATH}
  echo "# RVM bash completion
  [[ -r \"\$HOME/.rvm/scripts/completion\" ]] && source \"\$HOME/.rvm/scripts/completion\"" | sed -e 's/^[ ]*//' >> ${USER_PROFILE_PATH}
  source ${USER_PROFILE_PATH}
  rvm install 3.3.0 --autolibs=1
}

install_nodejs
install_rvm
